import {
  PlayListDetail,
  Privilege,
  PlayListSong,
  HotPlayListTag,
  MainTag,
  Collector,
} from "@/types/album";

import request from "../utils/request";

export function getPlayListDetail(params: { id: number; s?: number }) {
  return request<{
    code: number;
    playlist: PlayListDetail;
    privileges: Privilege[];
  }>({
    url: "/playlist/detail",
    method: "get",
    params: {
      ...params,
      timestamp: Date.now(),
    },
  });
}

export function getPlayListDynamic(id: number | string) {
  return request({
    url: "/playlist/detail/dynamic",
    method: "get",
    params: { id },
  });
}

export function getPlayListTracks(
  id: number | string,
  limit?: number,
  offset?: number
) {
  return request<{
    code: number;
    songs: PlayListSong[];
    privileges: Privilege[];
  }>({
    url: "/playlist/track/all",
    method: "get",
    params: { limit, offset, id, timestamp: Date.now() },
  });
}

export function getTopPlayList(params?: { limit?: number; offset?: number }) {
  return request<{
    code: number;
    lasttime: number;
    total: number;
    playlists: PlayListDetail[];
  }>({
    // url: '/top/playlist',
    url: "/top/playlist/highquality",
    method: "get",
    params,
  });
}

export function getTopPlayListTrue(params?: {
  cat: string;
  limit: number;
  offset: number;
}) {
  return request<{
    code: number;
    cat: string;
    playlists: PlayListDetail[];
    total: number;
  }>({
    url: "/top/playlist",
    method: "get",
    params,
  });
}

export function getPlayListCategoryDict() {
  return request<{ code: number; categories: { [key: number]: string } }>({
    url: "/playlist/catlist",
    method: "get",
  });
}

export function getHqListTags() {
  return request<{
    code: number;
    tags: MainTag[];
  }>({
    url: "/playlist/highquality/tags",
    method: "get",
  });
}

export function getHotListCategory() {
  return request<{ code: number; tags: HotPlayListTag[] }>({
    url: "/playlist/hot",
    method: "get",
  });
}

export function getPlaylistCollecter(params: {
  id: number | string;
  limit?: number;
  offset?: number;
}) {
  return request<{
    code: number;
    total: number;
    subscribers: Collector[];
  }>({
    url: "/playlist/subscribers",
    method: "get",
    params,
  });
}

export function getUsersPlaylist(uid: number | string) {
  return request<{
    code: number;
    more: boolean;
    playlist: PlayListDetail[];
    version: string;
  }>({
    url: "/user/playlist",
    method: "get",
    params: {
      uid,
    },
  });
}

export function getMyLikedMusic(uid: number | string) {
  return request<{
    checkPoint: number;
    code: number;
    ids: (number | string)[];
  }>({
    url: "/likelist",
    method: "get",
    params: { uid },
  });
}

export function CDMusicInPlaylist(
  op: keyof { add: string; del: string },
  pid: number | string,
  tracks: number | string
) {
  return request<{
    status: number;
  }>({
    url: "/playlist/tracks",
    method: "get",
    params: {
      op,
      pid,
      tracks,
    },
  });
}

export function updatePlaylistPlayCount(id: number | string) {
  return request<{
    code: 200;
  }>({
    url: "/playlist/update/playcount",
    method: "get",
    params: {
      id,
    },
  });
}
